﻿#region MIT Licence
/*
 * Copyright (C) 2014 PdfCreative
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
 * and associated documentation files (the "Software"), to deal in the Software without restriction, 
 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
 * sublicense, and/or sell copies of the Software, and to permit persons to whom 
 * the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included 
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 
 * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
#endregion

using System;
using System.Collections.Generic;
using System.Text;

using PdfCreative.Pdf.Writer;

namespace PdfCreative.Pdf.Graphics
{
    /// <summary>
    /// The Image class represents an image on a PDF page. The image is located on disk, as indicated by its
    /// Filename property. Images are added to a page or stencil using the Graphics class.
    /// </summary>
    public class Image : IResourceWriter
    {
        // Private fields
        // ==============
        #region Private fields
        private string _filename;
        #endregion



        // Public properties
        // =================
        #region Public properties
        /// <summary>
        /// True if this resource is a custom resource. False otherwise.
        /// </summary>
        public bool IsCustomResource { get { return false; } }

        /// <summary>
        /// Sets or retrieves the file name of the image.
        /// </summary>
        public string Filename
        {
            get { return _filename; }
        }
        #endregion



        // Base class overrides
        // ====================
        #region Object overrides
        /// <summary>
        /// Compares this image instance against another instance.
        /// </summary>
        /// <param name="obj">The other instance.</param>
        /// <returns>True if the other instance is not a Null reference, is an Image instance, and the two images
        /// have the same file name. False otherwise.</returns>
        public override bool Equals(object obj)
        {
            bool result = false;
            Image otherImage = obj as Image;

            if (null != otherImage)
                result = otherImage.Filename.Equals(this.Filename, StringComparison.InvariantCultureIgnoreCase);

            return result;
        }

        /// <summary>
        /// Retrieves the image's hash code.
        /// </summary>
        /// <returns>The image's hash code.</returns>
        public override int GetHashCode()
        {
            return _filename.GetHashCode();
        }

        /// <summary>
        /// Retrieves the string representation of the image.
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return String.Format("Image ('{0}')", _filename);
        }
        #endregion



        // Interface implementations
        // =========================
        #region IResourceWriter Members
        /// <summary>
        /// Returns the scope of this resource.
        /// </summary>
        public ResourceScope Scope
        {
            get { return ResourceScope.Document; }
        }

        /// <summary>
        /// Writes the resource.
        /// </summary>
        /// <param name="graphics">The graphics object.</param>
        /// <param name="writer">The PDF writer.</param>
        /// <param name="resourceReference">The resource reference.</param>
        /// <param name="scope">The resource.</param>
        public void WriteResource(Graphics graphics, PdfWriter writer, PdfResourceReference resourceReference, ScopedResource scope)
        {
            throw new NotImplementedException();
        }
        #endregion



        // Public constructor
        // ==================
        #region Public constructor
        /// <summary>
        /// Constructs a new Image instance.
        /// </summary>
        /// <param name="filename">The filename of the image.</param>
        /// <exception cref="ArgumentNullException">The filename can not be a Null reference.</exception>
        /// <exception cref="ArgumentException">The filename can not be an empty string.</exception>
        public Image(string filename)
        {
            if (null == filename)
                throw new ArgumentNullException("filename");

            if (String.Empty == filename)
                throw new ArgumentException("filename");

            _filename = filename;
        }
        #endregion

    } // Image class
}
